home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / dev / mui / MCC_HTMLtext.lha / MCC_HTMLtext / Developer / C / Examples / HTMLtext-DEMO.c
Encoding:
C/C++ Source or Header  |  1997-04-21  |  6.5 KB  |  225 lines

  1. // **********************************
  2. // HTMLtext-DEMO
  3. // (C)opyright by Dirk Holtwick, 1997
  4. // **********************************
  5.  
  6. // This demo is kind of a WYSIWYG editor for HTML.
  7. // Just edit the string in the gadget and you will
  8. // see the effect in the same moment.
  9.  
  10. // If you have problems, please report me the bug
  11. // and send me the text that leaded to confusion.
  12.  
  13. /// Includes
  14. #include <workbench/startup.h>
  15. #include <clib/alib_protos.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19. #include <proto/graphics.h>
  20. #include <proto/asl.h>
  21. #include <proto/utility.h>
  22. #include <proto/muimaster.h>
  23. #include <proto/icon.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. // #include <mui/html_mcc.h>
  28. #include "include/HTMLtext_mcc.h"
  29.  
  30. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  31.  
  32. extern struct Library *SysBase;
  33.  
  34. /*  ATTENTION !!!
  35. **  HTMLtext.mcc makes use of recursion and so you
  36. **  have to take care, that there is always
  37. **  enough space on the stack. The more the better!
  38. */
  39.  
  40. LONG __stack = 8192;
  41. ///
  42.  
  43. /// Demotext
  44. #define DEMOTEXT \
  45.    "<html>This <i>is a <small>small</small> <big>Demo</big></i> of " \
  46.    "the <b>HTMLtext class.</b><br> "\
  47.    "Try to drop a HTML file in this window! " \
  48.    "<p align=right>Yours Dirk</html>"
  49. ///
  50. /// Pointers
  51. APTR app;
  52. APTR window;
  53. APTR str;
  54. APTR html;
  55. APTR scroll;
  56. APTR url;
  57. ///
  58.  
  59. /// AppMsgFunc
  60. __saveds __asm LONG AppMsgFunc(register __a2 APTR obj, register __a1 struct AppMessage **x)
  61. {
  62.    /*
  63.     *   Very simple functions to parse the
  64.     *   AppMessage and set URL
  65.     *   (Taken from AppWindow.c)
  66.     */
  67.  
  68.    struct WBArg *ap;
  69.    struct AppMessage *amsg = *x;
  70.    static char buf[256];
  71.  
  72.    if(amsg->am_NumArgs)
  73.    {
  74.       ap=amsg->am_ArgList;
  75.       NameFromLock(ap->wa_Lock,buf,sizeof(buf));
  76.       AddPart(buf,ap->wa_Name,sizeof(buf));
  77.       set(obj,MUIA_HTMLtext_URL,buf);
  78.    }
  79.  
  80.    return(0);
  81. }
  82. ///
  83. /// Main
  84. int main(int argc,char *argv[])
  85. {
  86.    struct   Library *IntuitionBase;
  87.    int      ret=RETURN_ERROR;
  88.    static   const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };
  89.  
  90.    if(IntuitionBase = OpenLibrary("intuition.library", 36))
  91.    {
  92.       struct Library *MUIMasterBase;
  93.  
  94.       if(MUIMasterBase = OpenLibrary(MUIMASTER_NAME, 13))
  95.       {
  96.          ULONG signals;
  97.          BOOL running = TRUE;
  98.  
  99.          // Load the text
  100.          app = ApplicationObject,
  101.             MUIA_Application_Title      , "HTMLtext-DEMO",
  102.             MUIA_Application_Version    , "$VER: HTMLtext-DEMO 1.1 " __AMIGADATE__,
  103.             MUIA_Application_Copyright  , "(C)opyright by Dirk Holtwick 1997",
  104.             MUIA_Application_Author     , "Dirk Holtwick",
  105.             MUIA_Application_Description, "Uses the HTMLtext.mcc to display text.",
  106.             MUIA_Application_Base       , "HTMLTEXTDEMO",
  107.  
  108.             SubWindow, window = WindowObject,
  109.                MUIA_Window_Title, "HTMLtext-Demo © Dirk Holtwick, 1997",
  110.                MUIA_Window_ID   , MAKE_ID('D','E','M','O'),
  111.                MUIA_Window_UseRightBorderScroller, TRUE,
  112.                MUIA_Window_UseBottomBorderScroller, TRUE,
  113.                MUIA_Window_AppWindow, TRUE,
  114.  
  115.                WindowContents, VGroup,
  116.  
  117.                   Child, url = TextObject,
  118.                      TextFrame,
  119.                      MUIA_Font, MUIV_Font_Tiny,
  120.                      MUIA_Background, MUII_TextBack,
  121.                      End,
  122.  
  123.                   Child, scroll = ScrollgroupObject,
  124.                      MUIA_CycleChain, 1,
  125.                      MUIA_Scrollgroup_UseWinBorder, TRUE,
  126.                      MUIA_Scrollgroup_Contents, html = HTMLtextObject,
  127.                         TextFrame,
  128.                         MUIA_HTMLtext_Contents, DEMOTEXT,
  129.                         End,
  130.                      End,
  131.  
  132.                   Child, str = StringObject,
  133.                      StringFrame,
  134.                      MUIA_ObjectID, 1,
  135.                      MUIA_CycleChain, 1,
  136.                      MUIA_String_MaxLen, 1024,
  137.                      End,
  138.                   End,
  139.                End,
  140.             End;
  141.  
  142.          if(app)
  143.          {
  144.             /*** generate notifies ***/
  145.             DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  146.                app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  147.  
  148.             /*** after modification of string contents refresh HTML object ***/
  149.             DoMethod(str,MUIM_Notify,MUIA_String_Contents,MUIV_EveryTime,
  150.                html,3,MUIM_Set,MUIA_HTMLtext_Contents,MUIV_TriggerValue);
  151.  
  152.             /*** string gadgets will always be active ***/
  153.             DoMethod(str,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  154.                window,3,MUIM_Set,MUIA_Window_ActiveObject,str);
  155.  
  156.             /*** react if someone droped an icon on the HTML object ***/
  157.             DoMethod(html,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  158.                html,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  159.  
  160.             /*** display title in windows title bar ***/
  161.             DoMethod(html,MUIM_Notify,MUIA_HTMLtext_Title,MUIV_EveryTime,
  162.                window,3,MUIM_Set,MUIA_Window_Title,MUIV_TriggerValue);
  163.  
  164.             /*** display current URL ***/
  165.             DoMethod(html,MUIM_Notify,MUIA_HTMLtext_URL,MUIV_EveryTime,
  166.                url,3,MUIM_Set,MUIA_Text_Contents,MUIV_TriggerValue);
  167.  
  168.             /*** ready to open the window ... ***/
  169.             set(window,MUIA_Window_ActiveObject,str);
  170.             set(window,MUIA_Window_DefaultObject,str);
  171.             set(str, MUIA_String_Contents, DEMOTEXT);
  172.  
  173.             /*** Load string ***/
  174.             DoMethod(app, MUIM_Application_Load, MUIV_Application_Load_ENVARC);
  175.  
  176.             set(window,MUIA_Window_Open,TRUE);
  177.  
  178.             while (running)
  179.             {
  180.                switch(DoMethod(app,MUIM_Application_Input,&signals))
  181.                {
  182.                   case MUIV_Application_ReturnID_Quit:
  183.                      running = FALSE;
  184.                      break;
  185.                }
  186.  
  187.                if(running && signals)
  188.                   Wait(signals);
  189.             }
  190.  
  191.             set(window, MUIA_Window_Open, FALSE);
  192.  
  193.             DoMethod(app, MUIM_Application_Save, MUIV_Application_Save_ENVARC);
  194.  
  195.             MUI_DisposeObject(app);
  196.  
  197.             ret = RETURN_OK;
  198.          }
  199.          else
  200.          {
  201.             puts("Could not open application!");
  202.             ret = RETURN_FAIL;
  203.          }
  204.  
  205.          CloseLibrary(MUIMasterBase);
  206.       }
  207.       else
  208.       {
  209.          puts("Could not open muimaster.library v13!");
  210.          ret = RETURN_FAIL;
  211.       }
  212.  
  213.       CloseLibrary(IntuitionBase);
  214.    }
  215.    else
  216.    {
  217.       puts("Could not open intuition.library v36!");
  218.       ret = RETURN_FAIL;
  219.    }
  220.  
  221.    return(ret);
  222. }
  223. ///
  224.  
  225.